{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-01-19T02:20:10.550391Z",
     "start_time": "2024-01-19T02:20:10.542243600Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "raw, col = 120, 120\n",
    "stride = 400\n",
    "win = 512\n",
    "num_raw = np.ceil((raw - win) / stride + 1).astype(np.uint8)\n",
    "num_col = np.ceil((col - win) / stride + 1).astype(np.uint8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1\n"
     ]
    }
   ],
   "source": [
    "print(num_raw, num_col)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T02:20:11.599284400Z",
     "start_time": "2024-01-19T02:20:11.586761500Z"
    }
   },
   "id": "2aaa502fe83140b3"
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [],
   "source": [
    "total_process = int(num_col) * int(num_raw)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T02:20:14.048960300Z",
     "start_time": "2024-01-19T02:20:14.043665800Z"
    }
   },
   "id": "56a7e5d25d1e1f96"
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "1"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_process"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T02:20:15.014032200Z",
     "start_time": "2024-01-19T02:20:15.008100400Z"
    }
   },
   "id": "ea86ca2edc628e21"
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [],
   "source": [
    "for i in range(0):\n",
    "    print(i)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T02:23:53.139463400Z",
     "start_time": "2024-01-19T02:23:53.136425600Z"
    }
   },
   "id": "f7fcedde822f3c20"
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "outputs": [],
   "source": [
    "def img_to_patches(img, win, stride, Syn=True):\n",
    "    chl, raw, col = img.shape\n",
    "    if raw < win or col < win:\n",
    "        return np.zeros((chl, win, win, 0))\n",
    "    chl = int(chl)\n",
    "    num_raw = np.ceil((raw - win) / stride + 1).astype(np.uint8)\n",
    "    num_col = np.ceil((col - win) / stride + 1).astype(np.uint8)\n",
    "    count = 0\n",
    "    total_process = int(num_col) * int(num_raw)\n",
    "    img_patches = np.zeros([chl, win, win, total_process])\n",
    "    if Syn:\n",
    "        for i in range(num_raw):\n",
    "            for j in range(num_col):\n",
    "                if stride * i + win <= raw and stride * j + win <= col:\n",
    "                    img_patches[:, :, :, count] = img[:, stride * i: stride * i + win, stride * j: stride * j + win]\n",
    "                elif stride * i + win > raw and stride * j + win <= col:\n",
    "                    img_patches[:, :, :, count] = img[:, raw - win: raw, stride * j: stride * j + win]\n",
    "                elif stride * i + win <= raw and stride * j + win > col:\n",
    "                    img_patches[:, :, :, count] = img[:, stride * i: stride * i + win, col - win: col]\n",
    "                else:\n",
    "                    img_patches[:, :, :, count] = img[:, raw - win: raw, col - win: col]\n",
    "                count += 1\n",
    "    return img_patches\n",
    "patched_img = img_to_patches(np.ones((3, 120, 120)), 512, 400)\n",
    "for i in range(patched_img.shape[3]):\n",
    "    print(i)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T02:29:10.445610300Z",
     "start_time": "2024-01-19T02:29:10.438824600Z"
    }
   },
   "id": "9983f08608be5746"
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "outputs": [],
   "source": [
    "import h5py\n",
    "import os\n",
    "with h5py.File(\"../options/HQPs_pretrain.h5\", 'w') as h5f:\n",
    "    h5f.close()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T04:08:20.248449400Z",
     "start_time": "2024-01-19T04:08:20.220375400Z"
    }
   },
   "id": "26efa6c209464ebf"
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "data": {
      "text/plain": "3"
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int(np.log2(512 // 64))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T04:55:45.019494700Z",
     "start_time": "2024-01-19T04:55:45.011452900Z"
    }
   },
   "id": "3ee0695bbd67187d"
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "3"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "math.floor(math.sqrt(2565 * 4000) / 1000)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-01-19T06:22:07.250449500Z",
     "start_time": "2024-01-19T06:22:07.248351900Z"
    }
   },
   "id": "1255656ea91f6316"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "1a78d164d333211a"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
